﻿/*-----------------------------------------------
// File: SpeedBtn.cs
// Description: 
// Author: Shaobing	492057342@qq.com
-----------------------------------------------*/
using UnityEngine;
using System.Collections;
using System.Collections.Generic;

namespace Battle
{
    public class SpeedBtn : MonoBehaviour
    {
        public UISprite btnSprite;

        public string speed_1x_spriteName;
        public string speed_2x_spriteName;

        public void Refresh() {
            SwitchBtnEnum(BattleManager.Instance.curSpeedEnum);
        }

        void SwitchBtnEnum(BattleSpeed bs) {
            BattleManager.Instance.SetSpeed(bs);
            switch (bs) {
                case BattleSpeed._1x:
                    btnSprite.spriteName = speed_1x_spriteName;
                    break;
                case BattleSpeed._2x:
                    btnSprite.spriteName = speed_2x_spriteName;
                    break;
            }
        }

        void OnClick() {
            if (BattleManager.Instance.curSpeedEnum == BattleSpeed._1x)
            {
                if (StaticData.curBattleData.battleType == BattleType.PVE ||
                    StaticData.curBattleData.battleType == BattleType.FIELD_PVE ||
                    StaticData.curBattleData.battleType == BattleType.FIELD_BOSS)
                {
                    int level = Dict.Blo.DictConfigBlo.GetSkipBattleLimitLevel();
                    int vipLevel = Dict.Blo.DictConfigBlo.GetSkipBattleLimitVIPLevel();
                    if (StaticData.playerData.level >= level || StaticData.playerData.vip >= vipLevel)
                    {
                        SwitchBtnEnum(BattleSpeed._2x);
                    }
                    else
                    {
                        var str = string.Format(TableTextBlo.GetText("double_speed_battle_limit_text"), level, vipLevel);
                        BoxManager.CreatePopupTextBox(str);
                    }
                }
                else
                {
                    SwitchBtnEnum(BattleSpeed._2x);
                }
            }
            else if (BattleManager.Instance.curSpeedEnum == BattleSpeed._2x)
            {
                SwitchBtnEnum(BattleSpeed._1x);
            }
            else {
                SwitchBtnEnum(BattleSpeed._1x);
            }
        }

    }
}
